package com.csjbot.blackgaga.feature.navigation;

import android.text.TextUtils;

import com.csjbot.blackgaga.localbean.NaviBean;
import com.github.promeg.pinyinhelper.Pinyin;

import java.util.List;

/**
 * Created by xiasuhuei321 on 2017/12/15.
 * author:luo
 * e-mail:xiasuhuei321@163.com
 */

public class NaviTextHandler {
    public static boolean handle(String text) {
        String pinyin = strConvertPinyin(text);
        List<NaviBean> data = NaviAction.getInstance().getData();
        if (data == null || data.size() == 0) {
            return false;
        }
        for (String s : NAVI) {
            if (pinyin.contains(s)) {
                for (NaviBean naviBean : data) {
                    NaviAction.getInstance().guideSingle(naviBean);
                }
                return true;
            }
        }
        return false;
    }

    /**
     * 汉字转拼音方法
     *
     * @param text
     * @return
     */
    static String strConvertPinyin(String text) {
        if (TextUtils.isEmpty(text)) {
            return "";
        }
        StringBuilder sbPinyin = new StringBuilder();
        char[] texts = text.toCharArray();
        for (int i = 0; i < texts.length; i++) {
            sbPinyin.append(Pinyin.toPinyin(texts[i]));
        }
        return sbPinyin.toString();
    }

    static final String[] NAVI = {"DAOHANG", "DAIWOQU", "WOXIANGQU", "DAON", "QU", "ZAINA"};
}
